-
Notifications
You must be signed in to change notification settings - Fork 642
CASSGO-71 Make HostFilter interface easier to test #1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Currently external HostFilter implementations cannot be tested against HostFilter interface. To fix that the Accept method should have an interface as the parameter instead of HostInfo so that it is possible to mock it. Patch by: Mykyta Oleksiienko; Revieved by: ***; For CASSGO-71.
|
@joao-r-reis, could you please review the PR? |
tengu-alt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one comment. Overall LGTM
| String() string | ||
| } | ||
|
|
||
| // HostFilterFunc converts a func(host HostInfo) bool into a HostFilter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it also needs to be updated to func(host Host) bool
joao-r-reis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments.
I think there's other parts of the public API that need their HostInfo references changed to Host like observers, Iter and policies
|
|
||
| // TODO: This test failing with error due to "function dateof" on cassandra side. | ||
| // It was officially removed in version 5.0.0. The recommended replacement for dateOf is the toTimestamp function. | ||
| // As we are not testing against deprecated cassandra versions, it makes sense to update tests to keep them up to date |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was done in #1828 so once that is merged and this PR is rebased it should be fixed
| return | ||
| } | ||
|
|
||
| if d := host.Version().nodeUpDelay(); d > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this?
| Set(v string) error | ||
| UnmarshalCQL(info TypeInfo, data []byte) error | ||
| AtLeast(major, minor, patch int) bool | ||
| String() string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs some changes, just making an interface out of the methods of the private type feels wrong here, we shouldn't expose Set or Unmarshal method and we should definitely expose a way to get the actual version fields.
Ideally CassVersion would be:
type CassVersion interface {
Major() int
Minor() int
Patch() int
Qualifier() string
String() string
}
The methods on cassVersion can be converted into global private functions.
func (c *cassVersion) Set(v string) error
func (c *cassVersion) UnmarshalCQL(info TypeInfo, data []byte) error
func (c *cassVersion) unmarshal(data []byte) error {
func (c cassVersion) Before(major, minor, patch int) bool
func (c cassVersion) AtLeast(major, minor, patch int) bool
func parseCassVersion(v string) (CassVersion, error) {
c := &cassVersion{}
if v == "" {
return c, nil
}
return c.unmarshalCQL(nil, []byte(v))
}
func (c *cassVersion) unmarshalCQL(info TypeInfo, data []byte) error {
return c.unmarshal(data)
}
// can be kept as is
func (c *cassVersion) unmarshal(data []byte) error
// these two should just be global, private and have `CassVersion` parameters instead
func before(v1 CassVersion, v2 CassVersion) bool
func atLeast(v1 CassVersion, v2 CassVersion) bool
|
@OleksiienkoMykyta do you have time to address my review comments? We're trying to resolve the pending PRs for the 2.0 release |
|
After discussing with @jameshartig I've opened #1892 as an alternative |
|
Closed in favor of #1892 |
Closes #1311
Currently, external HostFilter implementations cannot be tested against HostFilter interface.
To fix that, the Accept method has an Host interface as the parameter instead of HostInfo so that it is possible to mock it.